import { BasicColumn, FormSchema } from '@apps/antd-admin/src/components/Table';
import { Api } from '../../wechat/data/api';

export const columns: BasicColumn[] = [
  {
    title: '标题',
    dataIndex: 'htmlTitle',
    width: 150,
  },
  {
    title: '编码',
    dataIndex: 'htmlCode',
    width: 120,
  },
  {
    title: '所属公众号',
    dataIndex: 'weChatName',
    width: 120,
  },
  {
    title: '排序',
    dataIndex: 'sortOrder',
    width: 100,
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    width: 150,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'htmlTitle',
    label: '标题',
    component: 'Input',
    colProps: { span: 4 },
  },
  {
    field: 'moduleId',
    label: '公众号',
    component: 'ApiSelect',
    colProps: { span: 5 },
    componentProps: {
      api: Api.list,
      showSearch: true,
      params: {},
      labelField: 'weChatName',
      valueField: 'weChatId',
      immediate: true,
    },
  },
];

export const formSchema: FormSchema[] = [
  {
    label: '标题',
    field: 'htmlTitle',
    component: 'Input',
    required: true,
  },
  {
    label: '编码',
    field: 'htmlCode',
    component: 'Input',
    required: true,
    dynamicDisabled: ({ values }) => {
      return !!values.htmlId;
    },
  },
  {
    label: '排序',
    field: 'sortOrder',
    component: 'InputNumber',
    required: true,
  },
  {
    label: '分组',
    field: 'htmlGroup',
    component: 'Input',
    required: false,
    defaultValue: 1,
    show: false,
  },
  {
    label: '所属公众号',
    field: 'moduleId',
    component: 'ApiSelect',
    required: true,
    componentProps: {
      api: Api.list,
      params: {},
      labelField: 'weChatName',
      valueField: 'weChatId',
      immediate: true,
    },
  },
  {
    label: '内容',
    field: 'htmlContent',
    component: 'TyEditor',
    required: true,
  },
];
